package cn.tedu.ivos.repair.service.imp;

import cn.tedu.ivos.repair.mapper.RepairMapper;
import cn.tedu.ivos.repair.pojo.dto.RepairParam;
import cn.tedu.ivos.repair.pojo.dto.RepairQuery;
import cn.tedu.ivos.repair.pojo.entity.Repair;
import cn.tedu.ivos.repair.pojo.vo.RepairVO;
import cn.tedu.ivos.repair.service.RepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RepairServiceImp implements RepairService {
    @Autowired
    RepairMapper repairMapper;
    @Override
    public List<RepairVO> selectRepair(RepairQuery repairQuery) {
        log.debug("查询维修业务开始: {}", repairQuery);
        Repair repair = new Repair();
        BeanUtils.copyProperties(repairQuery, repair);
        List<RepairVO> repairVOs =repairMapper.selectRepair(repair);
        log.debug("查询维修业务结束: {}", repairVOs);
        return repairVOs;

    }

    @Override
    public void addRepair(RepairParam repairParam) {
        log.debug("修改维修业务开始: {}", repairParam);
        if (repairParam.getId()!=null){
            Repair repair = new Repair();
            BeanUtils.copyProperties(repairParam, repair);
            repair.setUpdateTime(new Date());
            repairMapper.updateRepair(repair);
            log.debug("修改维修业务结束: {}", repair);
        }
        log.debug("添加维修业务开始: {}", repairParam);
        Repair repair = new Repair();
        BeanUtils.copyProperties(repairParam, repair);
        repair.setCreateTime(new Date());
        repairMapper.addRepair(repair);
        log.debug("添加维修业务结束: {}", repair);
    }

    @Override
    public void deleteRepair(Long id) {
        log.debug("删除维修业务开始: {}", id);
        repairMapper.deleteRepair(id);
        log.debug("删除维修业务结束: {}", id);
    }
}
